package com.ruoyi.management_controller.liaison_station.LiaisonStation.service.impl;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.management_controller.liaison_station.StreetInfo.domain.StreetInfo;
import com.ruoyi.management_controller.liaison_station.StreetInfo.mapper.StreetInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.management_controller.liaison_station.LiaisonStation.mapper.LiaisonStationMapper;
import com.ruoyi.management_controller.liaison_station.LiaisonStation.domain.LiaisonStation;
import com.ruoyi.management_controller.liaison_station.LiaisonStation.service.ILiaisonStationService;

/**
 * 联络站信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-09
 */
@Service
public class LiaisonStationServiceImpl implements ILiaisonStationService 
{
    @Autowired
    private LiaisonStationMapper liaisonStationMapper;

    @Autowired
    private StreetInfoMapper streetInfoMapper;

    /**
     * 查询联络站信息
     * 
     * @param id 联络站信息主键
     * @return 联络站信息
     */
    @Override
    public LiaisonStation selectLiaisonStationById(String id)
    {
        return liaisonStationMapper.selectLiaisonStationById(id);
    }

    public List<LiaisonStation> selectfbyStreetid(String id){
        return liaisonStationMapper.selectfbyStreetid(id);
    }
    /**
     * 查询联络站信息列表
     * 
     * @param liaisonStation 联络站信息
     * @return 联络站信息
     */
    @Override
    public List<LiaisonStation> selectLiaisonStationList(LiaisonStation liaisonStation)
    {
        return liaisonStationMapper.selectLiaisonStationList(liaisonStation);
    }

    /**
     * 新增联络站信息
     * 
     * @param liaisonStation 联络站信息
     * @return 结果
     */
    @Override
    public int insertLiaisonStation(LiaisonStation liaisonStation)
    {
        String streeId=liaisonStation.getStreetId();
        liaisonStation.setStreetName(streetInfoMapper.selectStreetInfoById(streeId).getStreetName());
        String[] array =liaisonStation.getRepresentatives().split(",");
        liaisonStation.setRepresentativesCount(Arrays.stream(array).count());
        return liaisonStationMapper.insertLiaisonStation(liaisonStation);
    }

    /**
     * 修改联络站信息
     * 
     * @param liaisonStation 联络站信息
     * @return 结果
     */
    @Override
    public int updateLiaisonStation(LiaisonStation liaisonStation)
    {
        String streeId=liaisonStation.getStreetId();
        liaisonStation.setStreetName(streetInfoMapper.selectStreetInfoById(streeId).getStreetName());
        String[] array =liaisonStation.getRepresentatives().split(",");
        liaisonStation.setRepresentativesCount(Arrays.stream(array).count());
        return liaisonStationMapper.updateLiaisonStation(liaisonStation);
    }

    /**
     * 批量删除联络站信息
     * 
     * @param ids 需要删除的联络站信息主键
     * @return 结果
     */
    @Override
    public int deleteLiaisonStationByIds(String[] ids)
    {
        return liaisonStationMapper.deleteLiaisonStationByIds(ids);
    }

    /**
     * 删除联络站信息信息
     * 
     * @param id 联络站信息主键
     * @return 结果
     */
    @Override
    public int deleteLiaisonStationById(String id)
    {
        return liaisonStationMapper.deleteLiaisonStationById(id);
    }



}
